1. Technical Field
The present invention relates to an improved data processing system. In particular, the present invention relates to mapped views of an object model in a data processing system. Still more particularly, the present invention relates to preserving relationships of mapped views in an object model in a data processing system.
2. Description of Related Art
In most development environments, developers generate a set of objects from a database model in order to import data into an application development tool. The database model comprises database tables and views. A view is a read only collection of columns from one or more database tables. A view may be used to normalize data from multiple database tables.
Currently, a view only contains columns from the base tables and it does not include constraints such as primary key and foreign key constraints. A primary key constraint contains a set of columns whose values uniquely identify an entry in a table. A foreign key constraint is used to create relationship between two tables. Foreign key constraints maintain referential integrity between two tables by ensuring values in the columns of the table owning the foreign key constraint match the column values from that primary key constraint of the target table. The columns of the foreign key constraint must match in order, type, and value of the primary key constraint of the target table. Primary key can be interchanged with primary key constraint and foreign key can be interchanged with foreign key constraint.
In some development environments, a virtual primary key for a database view can be obtained by the union of all primary key columns in the underlying database tables. However, there are no foreign keys associated with the virtual primary key. Since foreign keys do not exist in database views, modeled objects derived from these views are void of any relationships.
To alleviate this problem, some developers will change the view to extend its scope to include all related tables and columns of interest. However, this requires additional development efforts and causes the backend shape of the base object to change, since the view has to include all extended tables and columns. Thus, the purpose of the view is defeated or it becomes too normalized to be of any use.
Therefore, it would be advantageous to have a method and apparatus for programmatically discovering foreign keys in a view from the view definition in underlying base tables, such that relationships are automatically maintained in an object model.